import { Controller, Get, UseFilters, Res, Logger } from "@nestjs/common";
import { ConfigService } from "../config/config.service";
import { HttpExceptionFilter } from "../utils/httpexception";
import { Response } from "express";
import axios from "axios";

@Controller()
@UseFilters(HttpExceptionFilter)
export class VersionController {
    constructor(private readonly configService: ConfigService, private readonly logger: Logger) {}

    @Get("")
    async get(@Res() res: Response) {
        try {
            this.logger.log(`{/deploy-manager/v1/containerized/information/anyshare GET} start`);
            const { data } = await axios.get(
                `http://deploy-service.anyshare.svc.cluster.local:9703/api/deploy-manager/v1/containerized/information/anyshare`
            );
            this.logger.log(`{/deploy-manager/v1/containerized/information/anyshare GET} success`);
            res.status(200).json(data);
        } catch (ex) {
            if (ex.response) {
                throw ex;
            } else {
                this.logger.error(
                    `{/deploy-manager/v1/containerized/information/anyshare GET} ERROR 内部错误或网络异常`
                );
                throw {
                    message: "内部错误或网络异常",
                    response: {
                        code: 500,
                        cause: "内部错误或网络异常",
                    },
                };
            }
        }
    }
}
